<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;
use Common\Model\Cate;
//测试控制器
class IndexController extends Controller{

	//构造函数
	public function __init()
	{
	}
	
    //动作
    public function index(){
    	$cateModel = new Cate;
		$cates = $cateModel->get();//获取所有分类
		$cates=$cateModel->addsub($cates);//按照有没有子类 重新组装数据
		//p($cates);
		$cateA=$cateModel->where("pid=0")->get();//获取顶级分类
		
		foreach ($cateA as $k => $v) {
			$cateB=$cateModel->where("pid={$v['cid']}")->lists('cid');//获取2级分类
			if($cateB){
				$cateB=implode(',', $cateB);
				//p($cateB);
				$cateC[]=$cateModel->where("pid IN ({$cateB})")->get();//获取3级分类
			}else{
				$cateC[]=[];
			}
			
		}
		//p($cateModel->getLevel($cates,2));
//		p($cateC);
		View::with('cateC',$cateC);
		View::with('cates',$cates);
       View::make();
    }
}
